package com.wnxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @Classname TestController2
 * @Description :
 * @Date 2021/3/1 19:32
 * @Created by Yeheng
 */
@Controller
public class TestController2 {
    @Autowired
    RestTemplate template;

    @GetMapping("/get2")
    public String get2(String token, Model model){
        model.addAttribute("token",token);
        System.out.println(111111111);
        return "1";
    }

    @GetMapping("/logout")
    @ResponseBody
    public String logout(HttpServletRequest req){
        Cookie token = WebUtils.getCookie(req, "token");
        //消除本地cookie
        token.setMaxAge(0);

        String url = req.getRequestURL().toString();
        //远程调用是token进入登出名单
        template.getForObject("http://auth-service/logout?token="+token.getValue(),String.class);
        return "登出成功！！！！！！！！";
    }

}
